#-*- coding:utf-8 -*-
from __future__ import division
import func
import numpy as np
num = 0
def get_price_list(c_list):
    price_list = []
    global num
    #获取所有商品价格
    for p in c_list:                                                    # 每件商品
        p['offer'].sort(key=lambda x: x['timestamp'], reverse=True)     # 价格从新到旧排序
        result = False
        for offer in p['offer']:                                        # 找最新的非零价格
            if offer['info']:                                           # 一个时间点有信息
                for info in offer['info']:                              # 对此时间点的所有非零价格记录
                    price = func.get_price(info['price'])
                    #print info['price']
                    if price > 0.01:
                        result = True
                        price_list.append(price)
                #if result:
                #    break
        if not result:
            num += 1
            # func.print_info(p['offer'])
    """
    #获取商品价格分布
    max_num = max(price_list)
    min_num = min(price_list)
    gap = (max_num - min_num) / 10

    count_list = []
    gap_list = []
    for i in range(1, 10 + 1):
        count = 0
        for price in price_list:
            if (price >= min_num + gap * (i - 1) and price <= min_num + gap * i):
                count += 1
        gap_list.append(min_num + gap * (i - 1))
        count_list.append(count)
    gap_list.append(max_num)
    """
    n, bins = np.histogram(price_list, 10)
    count_list = list(n)
    gap_list = list(bins)
    return {'count': count_list,
            'range': [round(p, 2) for p in gap_list],
            'num': num
            }
